package net.starwifi.duobao.utils.sms;

import net.sf.json.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.List;

/**
 * Created by STX on 2015/9/29.
 */
public class SMSRequest {

    private String partnerId;

    private String partnerAcctName;

    private String phoneNumber;

    private String templateId;

    private List<String> datas;

    private String md5;

    public SMSRequest(String partnerId, String partnerAcctName, String phoneNumber, String templateId, List<String> datas,String partnerAuthCode) {
        this.partnerId = partnerId;
        this.partnerAcctName = partnerAcctName;
        this.phoneNumber = phoneNumber;
        this.templateId = templateId;
        this.datas = datas;
        this.md5 = makeSign(partnerAuthCode);
    }

    public SMSRequest(String phoneNumber, List<String> datas,String templateId) {
        this.partnerId = "100004";
        this.partnerAcctName = "starwifi";
        this.phoneNumber = phoneNumber;
        this.templateId = templateId;
        this.datas = datas;
        this.md5 = makeSign("343D35167272373596FBA8291C6AB3B8");
    }

    private String makeSign(String partnerAuthCode) {
        StringBuffer sb=new StringBuffer();
        sb.append(templateId);
        sb.append(phoneNumber);
        sb.append(partnerAuthCode);
        for(String data : datas){
            sb.append(data);
        }

        return DigestUtils.md5Hex(sb.toString()).toLowerCase();
    }

    public String toJsonStr(){
        return JSONObject.fromObject(this).toString();
    }

    public String getPartnerId() {
        return partnerId;
    }

    public void setPartnerId(String partnerId) {
        this.partnerId = partnerId;
    }

    public String getPartnerAcctName() {
        return partnerAcctName;
    }

    public void setPartnerAcctName(String partnerAcctName) {
        this.partnerAcctName = partnerAcctName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getTemplateId() {
        return templateId;
    }

    public void setTemplateId(String templateId) {
        this.templateId = templateId;
    }

    public List<String> getDatas() {
        return datas;
    }

    public void setDatas(List<String> datas) {
        this.datas = datas;
    }

    public String getMd5() {
        return md5;
    }

    public void setMd5(String md5) {
        this.md5 = md5;
    }
}
